(function ($) {
    $.fn.objDDNS = function (InIt) {

	var rdRadioWildcard;

        var controlMapExisting=new Array(0);
        var controlMapCurrent=new Array(0);

        var xmlName = '';

        this.onLoad = function () {
	    var index = 0;
	    this.loadHTML();
            document.getElementById("title").innerHTML = jQuery.i18n.prop("lDDNS");
	    var xml = getData(xmlName);

            var arrayLabels = document.getElementsByTagName("label");
            lableLocaliztion(arrayLabels);

            var buttonID = document.getElementById("btUpdate").id;
            buttonLocaliztion(buttonID);

	    document.getElementById('lDDNSErrorMsg').style.display = 'none';

	    var provider;
            provider=$(xml).find("provider").text();
	    document.getElementById("DDNSServicedrpdwn").selectedIndex = provider;
            controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/provider",provider);

	    var username;
            username=$(xml).find("username").text();
	    if ( username == "" ) {
		controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/username","");
		document.getElementById("tbddns_username").value = "";
	    }
	    else {
		controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/username",username);
		document.getElementById("tbddns_username").value = username;
	    }

	    var password;
            password=$(xml).find("password").text();
	    if ( password == "" ) {
		controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/password","");
		document.getElementById("tbddns_password").value = "";
	    }
	    else {
		controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/password",password);
		document.getElementById("tbddns_password").value = password;
	    }

	    var hostname;
            hostname=$(xml).find("hostname").text();
	    if ( hostname == "" ) {
		controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/hostname","");
		document.getElementById("tbddns_hostname").value = "";
	    }
	    else {
		controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/hostname",hostname);
		document.getElementById("tbddns_hostname").value = hostname;
	    }

	    var type;
            type=$(xml).find("type").text();
	    document.getElementById("DDNSTypedrpdwn").selectedIndex = type;
            controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/type",type);

	    var wildcard;
            wildcard=$(xml).find("wildcard").text();
	    rdRadioWildcard.setRadioButton(wildcard);
            controlMapExisting = g_objXML.putMapElement(controlMapExisting,index++, "RGW/dynamic_dns/wildcard",wildcard);

	    controlMapCurrent = g_objXML.copyArray(controlMapExisting,controlMapCurrent);

	    this.setObjectVisibility(provider);
        }

        this.onPost = function () {
	    if (this.isvalid()) {
		var _controlMap = this.getPostData();
		if(_controlMap.length>0) {
		    //alert(g_objXML.getXMLDocToString(g_objXML.createXML(_controlMap)));
		    postXML("dynamic_dns", g_objXML.getXMLDocToString(g_objXML.createXML(_controlMap)));
		    //this.onLoad();
		}
            }
        }
 this.onPostSuccess = function (){
        this.onLoad(false);
        }
	this.isvalid = function (){
	    var selIndex = document.getElementById("DDNSServicedrpdwn").selectedIndex;
	    if ( selIndex != 0 ) {
		if ( document.getElementById("tbddns_username").value == "" ) {
		    document.getElementById('lDDNSErrorMsg').style.display = 'block';
		    document.getElementById('lDDNSErrorMsg').innerHTML =  jQuery.i18n.prop('lDDNSErrUsernameEmpty');
		    return false;
		}
		else if ( document.getElementById("tbddns_password").value == "" ) {
		    document.getElementById('lDDNSErrorMsg').style.display = 'block';
		    document.getElementById('lDDNSErrorMsg').innerHTML =  jQuery.i18n.prop('lDDNSErrPasswordEmpty');
		    return false;
		}
		else if ( document.getElementById("tbddns_hostname").value == "" ) {
		    document.getElementById('lDDNSErrorMsg').style.display = 'block';
		    document.getElementById('lDDNSErrorMsg').innerHTML =  jQuery.i18n.prop('lDDNSErrHostnameEmpty');
		    return false;
		}
	    }
	    return true;
	}

        this.getPostData = function (){
            var index = 0;
            var mapData = new Array(0);
            controlMapCurrent[index++][1]=document.getElementById("DDNSServicedrpdwn").selectedIndex;
            controlMapCurrent[index++][1]=document.getElementById("tbddns_username").value;
            controlMapCurrent[index++][1]=document.getElementById("tbddns_password").value;
            controlMapCurrent[index++][1]=document.getElementById("tbddns_hostname").value;
            controlMapCurrent[index++][1]=document.getElementById("DDNSTypedrpdwn").selectedIndex;
            controlMapCurrent[index++][1]=rdRadioWildcard.getRadioButton();

	    mapData = g_objXML.copyArray(controlMapCurrent,mapData);
	    mapData = g_objXML.getChangedArray(controlMapExisting,mapData,true);
            return mapData;
        }

        this.loadHTML =  function() {
	    document.getElementById('Content').innerHTML ="";
	    document.getElementById('Content').innerHTML = callProductHTML("html/internet/dynamic_dns.html");
            rdRadioWildcard = $("#rdRadioWildcard").enabled_disabled("rdRadioWildcard");
        }

        this.setXMLName = function (_xmlname){
            xmlName = _xmlname;
        }

	this.setObjectVisibility = function (selIndex){
	    switch (selIndex) {
	           case "0":
 		           document.getElementById('lDDNSUsername').style.display = 'none';
 		           document.getElementById('tbddns_username').style.display = 'none';
 		           document.getElementById('lDDNSPassword').style.display = 'none';
 		           document.getElementById('tbddns_password').style.display = 'none';
 		           document.getElementById('lDDNSHostname').style.display = 'none';
 		           document.getElementById('tbddns_hostname').style.display = 'none';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
	                   break;
	           case "1":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'block';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'block';
 		           document.getElementById('lDDNSWildcard').style.display = 'block';
 		           document.getElementById('rdRadioWildcard').style.display = 'inline';
	                   break;
	           case "2":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
	                   break;
	           case "3":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
	                   break;
	           case "4":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
	                   break;
	           case "5":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'block';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'block';
 		           document.getElementById('lDDNSWildcard').style.display = 'block';
 		           document.getElementById('rdRadioWildcard').style.display = 'inline';
	                   break;
	           case "6":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'block';
 		           document.getElementById('rdRadioWildcard').style.display = 'inline';
	                   break;
	           case "7":
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
	                   break;
	    }
	}

        return this.each(function () {
	    });
    }
})(jQuery);

function serviceChange()
{
    var selIndex = document.getElementById("DDNSServicedrpdwn").selectedIndex;

    switch (selIndex) {
	           case 0:
 		           document.getElementById('lDDNSUsername').style.display = 'none';
 		           document.getElementById('tbddns_username').style.display = 'none';
 		           document.getElementById('lDDNSPassword').style.display = 'none';
 		           document.getElementById('tbddns_password').style.display = 'none';
 		           document.getElementById('lDDNSHostname').style.display = 'none';
 		           document.getElementById('tbddns_hostname').style.display = 'none';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 1:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'block';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'block';
 		           document.getElementById('lDDNSWildcard').style.display = 'block';
 		           document.getElementById('rdRadioWildcard').style.display = 'block';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 2:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 3:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 4:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 5:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'block';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'block';
 		           document.getElementById('lDDNSWildcard').style.display = 'block';
 		           document.getElementById('rdRadioWildcard').style.display = 'block';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 6:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'block';
 		           document.getElementById('rdRadioWildcard').style.display = 'block';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	           case 7:
 		           document.getElementById('lDDNSUsername').style.display = 'block';
 		           document.getElementById('tbddns_username').style.display = 'block';
 		           document.getElementById('lDDNSPassword').style.display = 'block';
 		           document.getElementById('tbddns_password').style.display = 'block';
 		           document.getElementById('lDDNSHostname').style.display = 'block';
 		           document.getElementById('tbddns_hostname').style.display = 'block';
 		           document.getElementById('lDDNSType').style.display = 'none';
 		           document.getElementById('DDNSTypedrpdwn').style.display = 'none';
 		           document.getElementById('lDDNSWildcard').style.display = 'none';
 		           document.getElementById('rdRadioWildcard').style.display = 'none';
		           document.getElementById('lDDNSErrorMsg').style.display = 'none';
	                   break;
	    }

}
